import { userInfoAction, useAppDispatch, useAppSelector, store } from '@/store';

// 获取用户信息
export function useUserInfo() {
  const { userInfo } = useAppSelector(store => ({
    userInfo: store.userInfo,
  }));

  return userInfo;
}

// 更新用户信息
export function useUserInfoSetter() {
  const dispatch = useAppDispatch();
  const { userInfo: state } = store.getState();

  function updateUserInfo(userInfo: typeof state) {
    dispatch(userInfoAction.setUserInfo(userInfo));
  }

  return { updateUserInfo };
}
